package com.mmlc.network.iml;

import android.content.Context;
import android.view.View;

import com.androidnetframe.ConfigUtil;
import com.androidnetframe.exception.BaseProcessCodeType;
import com.androidnetframe.exception.CodeTypeObject;
import com.mmlc.meimei.lichengkongjian.R;

/**
 * @author 何强
 *         2015-11-9
 */
public class ProcessCodeType implements BaseProcessCodeType {
    /**
     * @param context
     */
    public Context context;

    public ProcessCodeType() {
        context = ConfigUtil.context;
    }

    /**
     * 当发起网络请求时，应该显示一个网络加载提示框
     */
    @Override
    public CodeTypeObject processRequestNetLoadding() {
        CodeTypeObject codeTypeObject = new CodeTypeObject();
        codeTypeObject.codeType = CodeTypeObject.loadding;
        codeTypeObject.view = View.inflate(context, R.layout.overide_loadding, null);
        codeTypeObject.haveRefreshButton = false;
        codeTypeObject.shortShowView = true;
        codeTypeObject.isDerectShow = false;
        return codeTypeObject;
    }

    /**
     * 网络数据请求失败的异常处理
     */
    @Override
    public CodeTypeObject processConnectFailed() {
        CodeTypeObject codeTypeObject = new CodeTypeObject();
        codeTypeObject.view = View.inflate(context, R.layout.overide_request_failed, null);
        codeTypeObject.isDerectShow = false;
        codeTypeObject.codeType = CodeTypeObject.connectFailed;
        return codeTypeObject;
    }

    @Override
    public CodeTypeObject processNoNet() {
        CodeTypeObject codeTypeObject = new CodeTypeObject();
        codeTypeObject.view = View.inflate(context, R.layout.overide_request_no_net, null);
        codeTypeObject.isDerectShow = false;
        codeTypeObject.codeType = CodeTypeObject.noNet;
        return codeTypeObject;
    }

    @Override
    public CodeTypeObject processNoData() {
        CodeTypeObject codeTypeObject = new CodeTypeObject();
        codeTypeObject.view = View.inflate(context, R.layout.overide_no_data, null);
        codeTypeObject.isDerectShow = false;
        codeTypeObject.codeType = CodeTypeObject.noData;
        return codeTypeObject;
    }
}
